package ${packageName}.viewModel;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import ${applicationPackage}.R;
import ${applicationPackage}.BR;
import ${packageName}.adapter.${adapterName};
import ${packageName}.item.${itemViewModelName};

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.binding.command.BindingConsumer;
import me.goldze.mvvmhabit.utils.ToastUtils;
import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter;
import me.tatarka.bindingcollectionadapter2.ItemBinding;


public class ${viewModelName} extends BaseViewModel{
   
    public ${viewModelName} (@NonNull Application application) {
        super(application);
        //模拟3个ViewPager页面
        for (int i = 1; i <= 3; i++) {
            ${itemViewModelName} itemViewModel = new ${itemViewModelName}(this, "第" + i + "个页面");
            items.add(itemViewModel);
        }
    }

    //给ViewPager添加ObservableList
    public ObservableList<${itemViewModelName}> items = new ObservableArrayList<>();
	
    //给ViewPager添加ItemBinding
    public ItemBinding<${itemViewModelName}> itemBinding = ItemBinding.of(BR.viewModel, R.layout.${itemLayoutName});
	
    //给ViewPager添加PageTitle
    public final BindingViewPagerAdapter.PageTitles<${itemViewModelName}> pageTitles = new BindingViewPagerAdapter.PageTitles<${itemViewModelName}>() {
        @Override
        public CharSequence getPageTitle(int position, ${itemViewModelName} item) {
            return "条目" + position;
        }
    };
    
	//给ViewPager添加Adpter，使用自定义的Adapter继承BindingViewPagerAdapter，重写onBindBinding方法
    public final ${adapterName} adapter = new ${adapterName}();
	
    //ViewPager切换监听
    public BindingCommand<Integer> onPageSelectedCommand = new BindingCommand<>(new BindingConsumer<Integer>() {
        @Override
        public void call(Integer index) {
            ToastUtils.showShort("ViewPager切换：" + index);
        }
    });
}
